<template>
  <div class="app-container">

    <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery">


      <el-col :span="6">
        <el-form-item label="业务分类:" prop="categoryName">
          <el-input v-model="queryParams.categoryName" clearable placeholder="请输入业务分类名称"></el-input>
        </el-form-item>
      </el-col>


    </SearchContent>

    <div class="card-wrap padding20" :model="queryParams" ref="queryForm" label-width="86px">
      <div class="table-title-wrap justify-end">
        <el-button type="primary" size="mini" @click="handleAdd"
                   v-hasPermi="['demo:demo:add']">新增</el-button>
      </div>

      <el-table v-loading="loading" :data="dataList" border>

        <el-table-column label="ID" align="center" prop="tagId" />
        <el-table-column label="业务分类名称" align="center" prop="categoryName" />
        <el-table-column label="业务分类描述" align="center" prop="tagRemark" />
        <el-table-column label="操作" align="center" fixed="left">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
                       v-hasPermi="['demo:demo:edit']">编辑</el-button>
            <el-button size="mini" type="text" @click="handleDelete(scope.row)"
                       v-hasPermi="['demo:demo:edit']">删除</el-button>

          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList" />
    </div>


    <!-- 添加或修改测试单表对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="45%">
      <el-form ref="form" :rules="rules" :model="form" label-width="120px" @submit.native.prevent>

          <el-row >
            <el-col :span="20">

              <el-form-item label="业务分类名称:" prop="categoryName">

                <el-input v-model="form.categoryName" @keyup.enter.native="submitForm" clearable placeholder="请输入业务分类名称"></el-input>

              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="备注:" prop="remark">

                <el-input v-model="form.remark"
                          type="textarea"
                          :rows="2"
                          clearable placeholder="请输入备注"></el-input>

              </el-form-item>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" >
        <el-button @click="cancel">{{ isNew ? '取消' : '关闭' }}</el-button>
        <el-button :loading="buttonLoading" type="primary" @click="submitForm" v-if="isNew">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
// import { getModelData} from "@/api/zcwh/vehicleModelApi";
// import { getToken } from "@/utils/auth";
// import EInput from "../../components/from_table/EInput.vue";
// import ESelect from "../../components/from_table/ESelect.vue";
// import SearchMixin from '@/mixin/index';
import SearchContent from "@/components/SearchContent/index.vue";
import {delModel} from "@/api/zcwh/vehicleModelApi";

export default {
  // name: "VehicleModelList",
  components: {
    // 'e-input': EInput,
    SearchContent
    // 'e-select': ESelect,
  },
  // mixins:[SearchMixin],
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      isNew:true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        categoryName:''
      },

      total: 0,
      dataList: [],

      // 表单参数
      form: {
        categoryName: "",
        remark: "",
      },
      // 表单校验
      rules: {
        categoryName: [
          { required: true, message: "业务分类名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
  },
  methods: {
    /** 查询测试单表列表 */
    getList() {
      this.loading = true;


      getModelData(this.queryParams).then(res => {
        if (res.code == "200") {
          const { rows, total } = res
          this.dataList = rows
          this.total = total
          this.loading = false;
        }

      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        categoryName: "",
        remark: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        categoryName:''
      },
      // this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isNew = true
      this.title = "新增业务分类";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.isNew = true
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      // getCarBasic(id).then(response => {
      //
      //   this.loading = false;
      //   this.form = response.data;
      //   this.form.maxRegYear = response.data.maxRegYear + ""
      //   this.form.minRegYear = response.data.minRegYear + ''
      //   this.form.stopMakeYear = response.data.stopMakeYear + ''
      //   this.form.brandId = response.data.carBrandId
      //   this.form.seriesId = response.data.carSeriesId
      //   this.form.seriesGroupId = response.data.carSeriesGroupId
      //
      //   this.getSeriesNames(this.form.brandId)
      //
      //
      //   this.getSeriesGroup({ brandName: this.form.brandName, carBrandId: this.form.brandId })
      //   this.open = true;
      //   this.title = "编辑";
      //
      //
      // });
      this.$forceUpdate();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否删除？').then(() => {
        this.loading = true;
        return delModel(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id) {
            updateCar(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            carBrandAdd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },

  }
};
</script>


<style lang="scss" scoped>
.pagination-container{
  padding: 0 20px 50px !important;
}


.form-dialog {
  ::v-deep .el-dialog__header {
    padding: 10px 20px;
    border-bottom: 1px solid #DCDFE6;

    .el-dialog__headerbtn {
      top: 15px;
    }
  }

  .box-card {
    margin-bottom: 20px;

    .card-title {
      font-size: 16px;
      position: relative;
      margin-left: 8px;
      padding: 0;
    }

    .card-title::after {
      content: '';
      width: 4px;
      height: 18px;
      background-color: aqua;
      display: block;
      position: absolute;
      left: -12px;
      top: 2px;
    }
  }

}
</style>
